package com.airnews.ticket.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "com.airnews.ticket";
	private static final int DATABASE_VERSION = 3;//修改这个值可以升级数据库
	
	//系统常用参数设置
	public static final String SYSTEM_TABLE_NAME = "system_set";
	//乘客表
	public static final String PASSENGER_TABLE_NAME = "passengers";
	//联系人表
	public static final String CONTACTOR_TABLE_NAME = "contactors";
	//收件人表
	public static final String ITINERARY_TABLE_NAME = "itinerarys";
	//常旅客表
	public static final String MILEAGER_TABLE_NAME = "mileagers";
	
	//保存渠道ID的表
	public static final String CHANNEL_TABLE_NAME = "channel";
    
	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

 
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE " + PASSENGER_TABLE_NAME + " ("
				+ BaseColumns._ID + " integer primary key autoincrement, "
				+ "passengerName text,passengerType text" 
				+ " ,idType text,idNo text,birthday text,passengerMobile text,email text,sex text,setDefault text);");
		
		db.execSQL("CREATE TABLE " + CONTACTOR_TABLE_NAME + " ("
				+ BaseColumns._ID + " integer primary key autoincrement, "
				+ "contactNO text,contactName text" 
				+ " ,phone text,email text,sex text,birthday text,setDefault text);");
		
		db.execSQL("CREATE TABLE " + ITINERARY_TABLE_NAME + " ("
				+ BaseColumns._ID + " integer primary key autoincrement, "
				+ "consigneeName text,consigneePhone text" 
				+ " ,consigneeAddress text,consigneeZIP text,setDefault text);");
		
		db.execSQL("CREATE TABLE " + MILEAGER_TABLE_NAME + " ("
				+ BaseColumns._ID + " integer primary key autoincrement, "
				+ "mileagerCardAirline text,mileagerCardNumber text" 
				+ " ,mileagerInfo text,mileagerNO text,passengerNO text);");
		
		db.execSQL("CREATE TABLE "
				+ SYSTEM_TABLE_NAME +  " ("
				+ BaseColumns._ID + " integer primary key autoincrement, systemType text,systemName text);");
		
		Log.i("", "CREATE TABLE　SYSTEM_TABLE_NAME");
		Log.i("", "CREATE TABLE　PASSENGER_TABLE_NAME");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
//		db.execSQL("DROP TABLE IF EXISTS " + ORDER_TABLE_NAME);
//		db.execSQL("DROP TABLE IF EXISTS " + PASSENGER_TABLE_NAME);
		Log.i("", "DROP TABLE　>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		db.execSQL("DROP TABLE IF EXISTS " + SYSTEM_TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + PASSENGER_TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + CONTACTOR_TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + ITINERARY_TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + MILEAGER_TABLE_NAME);
		onCreate(db);
	}

}
